package testing;

import static org.junit.Assert.*;


import java.util.HashSet;

import org.junit.Test;

import hypeerweb.Node;
import hypeerweb.SimplifiedNodeDomain;

/**
 * A class designed to test Node
 *
 * @author brinkerhoff_kendra
 */
public class NodeTest {

	@Test
	public void testConstructSimplifiedNodeDomain() {
		Node n0 = new Node(0);
		Node n1 = new Node(1);
		
		n0.addNeighbor(n1);
		n0.setFold(n1);
		
		SimplifiedNodeDomain s0 = n0.constructSimplifiedNodeDomain();
		assertTrue(s0.getWebId() == 0);
		assertTrue(s0.getFold() == 1);
		assertTrue(s0.getInverseSurrogateFold() == -1);
		assertTrue(s0.getNeighbors().size() == 1);
		assertTrue(s0.getUpPointers().size() == 0);
		assertTrue(s0.getDownPointers().size() == 0);
	}

	@Test
	public void testGetHeight() {
		Node n0 = new Node(0);
		Node n1 = new Node(1);
		Node n2 = new Node(2);
		
		n0.setFold(n1);
		n0.addNeighbor(n1);
//		n0.addNeighbor(n2);
		
		n1.setFold(n2);
		n1.addNeighbor(n0);
		n1.addNeighbor(n2);
		n1.addUpPointer(n2);
		
		n2.setFold(n1);
		n2.addNeighbor(n0);
		n2.addDownPointer(n1);
		
		assertTrue(n0.getHeight() == 1);
		assertTrue(n1.getHeight() == 2);
		assertTrue(n2.getHeight() == 2);
	}

	@Test
	public void testGetWebIds() {
		Node n0 = new Node(0);
		Node n1 = new Node(1);
		Node n2 = new Node(2);
		
		HashSet<Node> nodes = new HashSet<Node>();
		nodes.add(n0);
		nodes.add(n1);
		nodes.add(n2);
		
		HashSet<Integer> ids = n0.getWebIds(nodes);
		
		int id = 0;
		for (Integer i : ids) {
			assertTrue(i == id++);
		}
	}
}
